package com.lc.qianrenshiye;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.zcx.helper.activity.AppV4PictureActivity;
import com.zcx.helper.util.UtilSDCard;


/**
 * Created by Administrator on 2016/3/14.
 */
public abstract class BasePictureActivity extends AppV4PictureActivity {

    private static String[] PERMISSIONS_STORAGE = {
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Check if we have write permission
        int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (permission != PackageManager.PERMISSION_GRANTED) {
            // We don't have permission so prompt the user
            ActivityCompat.requestPermissions(
                    this,
                    PERMISSIONS_STORAGE,
                    1
            );
        }

        //无title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    }

    public void setBackTrue() {

        try {

            findViewById(R.id.title_ll).setVisibility(View.VISIBLE);
            findViewById(R.id.title_back_rl).setVisibility(View.VISIBLE);
            findViewById(R.id.title_back_rl).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    public void setTitleName(String name) {

        try {

            findViewById(R.id.title_ll).setVisibility(View.VISIBLE);

//            findViewById(R.id.title_name_tv).setVisibility(View.VISIBLE);
            if (name.length() > 10) {

                name = name.substring(0, 10) + "...";

            }
            ((TextView) findViewById(R.id.title_name_tv)).setText(name);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

//    public void setBackTrue() {
//
//        try {
//
//            findViewById(R.id.title_back_rl).setVisibility(View.VISIBLE);
//            findViewById(R.id.title_back_rl).setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    finish();
//                }
//            });
//
//        } catch (Exception e) {
//
//            e.printStackTrace();
//
//        }
//
//    }
//
//    public void setTitleName(String name) {
//
//        try {
//
//            findViewById(R.id.title_name_ll).setVisibility(View.VISIBLE);
//            if (name.length() > 10) {
//
//                name = name.substring(0, 10) + "...";
//
//            }
//            ((TextView) findViewById(R.id.title_name_tv)).setText(name);
//
//        } catch (Exception e) {
//
//            e.printStackTrace();
//
//        }
//
//    }

    @Override
    protected String getCameraAbsolutePath() {

        return UtilSDCard.getSDCardPath() + "QianRenShiYe/";

    }

//    @Override
//    protected void onResume() {
//        super.onResume();
//
//        JPushInterface.onResume(this);
//
//        // 集成基本统计分析,初始化 Session
//        MobclickAgent.onResume(this);
//
//    }
//
//    @Override
//    protected void onPause() {
//        super.onPause();
//
//        JPushInterface.onPause(this);
//
//        // //集成基本统计分析, 结束 Session
//        MobclickAgent.onPause(this);
//
//    }

}
